package com.lujieni.springbootflowable;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;

/**
 * 包容网关
 */
@SpringBootTest
class SpringbootFlowableApplicationTests7 {
    
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private RuntimeService runtimeService;

    @Test
    void deploy() {
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("process/holiday4.bpmn20.xml")
                .name("包容网关")
                .deploy();
        System.out.println(deployment.getId());
    }


    /**
     * 包容网关如果没有1个符合条件的子节点会报错
     */
    @Test
    void startProcess() {
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("num",6);
        runtimeService.startProcessInstanceById("holiday4:1:1d4e4bf5-8e55-11f0-bcf1-5847ca7eb09c", variables);
    }

    @Test
    public void completeTask(){
        TaskService taskService = processEngine.getTaskService();
        taskService.complete("487cdf44-8e56-11f0-9d2d-5847ca7eb09c");
    }

}
